package com.eims.sls_app.ui;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.json.JSONException;
import org.json.JSONObject;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Editable;
import android.text.Html;
import android.text.Selection;
import android.text.Spannable;
import android.text.Spanned;
import android.text.TextWatcher;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import bls.juejin.cn.R;
import com.eims.sls_app.dataaccess.DtMatchBJDC;
import com.eims.sls_app.dataaccess.JC_Details;
import com.eims.sls_app.dataaccess.SelectedNumbers;
import com.eims.sls_app.dataaccess.Show_JC_Details;
import com.eims.sls_app.dataaccess.utils.HttpUtils;
import com.eims.sls_app.protocol.MD5;
import com.eims.sls_app.protocol.RspBodyBaseBean;
import com.eims.sls_app.ui.adapter.ExpandAdapterbjdcPassMore;
import com.eims.sls_app.ui.adapter.ExpandAdapterbjdcPassSingle;
import com.eims.sls_app.ui.adapter.MyBetLotteryBJDCAdapter;
import com.eims.sls_app.ui.adapter.SelectPasstype_List_BJDCAdapter;
import com.eims.sls_app.ui.adapter.SelectPasstype_List_BJDCSFAdapter;
import com.eims.sls_app.ui.adapter.SelectPasstype_List_JCAdapter;
import com.eims.sls_app.utils.App;
import com.eims.sls_app.utils.AppTools;
import com.eims.sls_app.utils.App;
import com.eims.sls_app.utils.ColorUtil;
import com.eims.sls_app.utils.JiangjinTools;
import com.eims.sls_app.utils.NumberTools;
import com.eims.sls_app.view.ConfirmDialog;
import com.eims.sls_app.view.MyListView2;
import com.eims.sls_app.view.MyToast;
import com.eims.sls_app.view.SelectBjdcPassTypePopupWindow;
import com.eims.sls_app.view.SelectBjdcsfPassTypePopupWindow;
import com.handmark.pulltorefresh.library.internal.Utils;

/**
 * 功能：投注页面 版本
 * 
 * @author Kinwee 修改日期2014-12-11
 */
public class Bet_BJDC_Activity extends MyBaseActivity implements OnClickListener {
	private final static String TAG = "Bet_BJDC_Activity";
	/**
	 * 新添加的
	 */
	private ListView passType_list;
	private SelectPasstype_List_BJDCAdapter listAdapter;
	private SelectPasstype_List_BJDCSFAdapter listAdapter_sf;
	/* 头部 */
	private RelativeLayout layout_main;// 主
	private ImageButton btn_back; // 返回
	private ImageView iv_up_down;// 玩法提示图标
	private Button btn_playtype;// 玩法
	private ImageButton btn_help;// 帮助
	private ConfirmDialog dialog;// 提示框
	private String SucJinECost, SucCaiJinCost, SuccMoney;
	private DecimalFormat format = new DecimalFormat("#####0.00");
	/* 尾部 */
	private Button btn_follow; // 发起合买
	private Button btn_clearall; // 清除全部
	private Button btn_submit; // 付款
	public TextView tv_tatol_count;// 总注数
	public TextView tv_tatol_money;// 总钱数

	private String opt = "11"; // 格式化后的 opt
	private String auth, info, time, imei, crc; // 格式化后的参数
	private LinearLayout btn_continue_select;// 继续选择比赛
	private ImageView bet_btn_deleteall;// 清空
	private TextView bet_tv_guize; // 委托投注规则
	public static ArrayList<JC_Details> list_JC_Details;
	private RelativeLayout layout_notjc;// 非竞彩布局
	private LinearLayout layout_jc;// 竞彩布局

	private TextView tv_show_passway;
	private TextView tv_show_passway2, tv_show_passway3;// 过关
	private RelativeLayout layout_cbs;// 复选框布局

	private MyListView2 bet_lv_scheme;// 自定义listview
	public MyBetLotteryBJDCAdapter adapter;
	private Intent intent;
	private int playtype;
	private int passtype;
	private long sumCount, totalMoney; // 方案总注数 // 方案总金额
	private EditText et_bei; // 用户输入的倍数
	private MyHandler myHandler;
	private MyAsynTask myAsynTask;

	private CheckBox bet_cb_stopfollow;
	private LinearLayout ll_pass2;
	private int isStopChase = 1;
	private int ishandsel = 0;
	private SelectBjdcPassTypePopupWindow selectPTpop;// 选择过关方式
	private SelectBjdcsfPassTypePopupWindow selectPTpopsf;
	private ArrayList<String> selectPasstype = new ArrayList<String>();// 选择的过关方式
	private int viewPagerCurrentIndex = 0;// 过关类型 0.多串1 1.多串多
	private List<String> eachSelectDT;
	private int countDan;// 胆的个数
	private int dtCount;// 获取已选择的比赛场次
	private String passStr = "";
	public TextView tv_jiangjin;// 总奖金
	private static LinearLayout layout_tip_jiangjin;
	private List<Show_JC_Details> list_Show = new ArrayList<Show_JC_Details>();// 用来计算奖金的
	private Map<String, String> max_peilv = new HashMap<String, String>();
	private Map<String, String> min_peilv = new HashMap<String, String>();
	private List<Double> list_max_jiangjin = new ArrayList<Double>();
	private List<Double> list_min_jiangjin = new ArrayList<Double>();
	private double max_jiangjin, min_jiangjin;
private   TextView tvFollow;

	private   RelativeLayout  lrfoot1;
	private   RelativeLayout	lrfoot2,lrfoot3;

	private  View viewLine3;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// 设置无标题
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_bet_bjdc);
		App.activityS.add(this);
		App.activityS1.add(this);
		findView();
		playtype = getIntent().getIntExtra("playtype", 1);
		passtype = getIntent().getIntExtra("passtype", 0);
	}

	/** 初始化UI */
	private void findView() {
		myHandler = new MyHandler();
		tv_jiangjin = (TextView) this.findViewById(R.id.tv_jiangjin); // 奖金
		layout_tip_jiangjin = (LinearLayout) findViewById(R.id.layout_tip_jiangjin); // 奖金

		ll_pass2 = (LinearLayout) findViewById(R.id.ll_pass2);
		btn_back = (ImageButton) findViewById(R.id.btn_back);
		btn_playtype = (Button) findViewById(R.id.btn_playtype);
		btn_help = (ImageButton) findViewById(R.id.btn_help);
		iv_up_down = (ImageView) findViewById(R.id.iv_up_down);
		btn_clearall = (Button) findViewById(R.id.btn_clearall);
		btn_submit = (Button) findViewById(R.id.btn_submit);
		btn_continue_select = (LinearLayout) this
				.findViewById(R.id.btn_continue_select);
		bet_btn_deleteall = (ImageView) this
				.findViewById(R.id.bet_btn_deleteall);
		btn_follow = (Button) this.findViewById(R.id.btn_follow);
		et_bei = (EditText) this.findViewById(R.id.et_bei);

		tv_tatol_count = (TextView) this.findViewById(R.id.tv_tatol_count);
		tv_tatol_money = (TextView) this.findViewById(R.id.tv_tatol_money);
		bet_cb_stopfollow = (CheckBox) this
				.findViewById(R.id.bet_cb_stopfollow);

		bet_tv_guize = (TextView) this.findViewById(R.id.bet_tv_guize);
		bet_lv_scheme = (MyListView2) this.findViewById(R.id.bet_lv_scheme);
		layout_notjc = (RelativeLayout) this.findViewById(R.id.layout_notjc);
		layout_jc = (LinearLayout) this.findViewById(R.id.layout_jc);
		layout_main = (RelativeLayout) this.findViewById(R.id.layout_main);
		tv_show_passway = (TextView) this.findViewById(R.id.tv_show_passway);
		tv_show_passway2 = (TextView) this.findViewById(R.id.tv_show_passway2);
		tv_show_passway3 = (TextView) this.findViewById(R.id.tv_show_passway3);

		tv_show_passway.setVisibility(View.VISIBLE);
		tv_show_passway2.setVisibility(View.VISIBLE);
		tv_show_passway3.setVisibility(View.GONE);
		layout_cbs = (RelativeLayout) this.findViewById(R.id.layout_cbs);
		btn_playtype.setText("北京单场投注单");

		passType_list = (ListView) findViewById(R.id.select_middle);
		listAdapter = new SelectPasstype_List_BJDCAdapter(
				getApplicationContext(), countDan, dtCount,
				viewPagerCurrentIndex, playtype);
		passType_list.setAdapter(listAdapter);
		tvFollow= (TextView) findViewById(R.id.tv_bonus);

		lrfoot1= (RelativeLayout) findViewById(R.id.layout_left1);
		lrfoot2= (RelativeLayout) findViewById(R.id.lrfoot2);
		lrfoot3= (RelativeLayout) findViewById(R.id.rl_bonus);

		LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.FILL_PARENT, 1.2f);
		LinearLayout.LayoutParams lp2 = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.FILL_PARENT, 1.5f);
		LinearLayout.LayoutParams lp3 = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.FILL_PARENT, 0.3f);
		lrfoot1.setLayoutParams(lp);
		lrfoot2.setLayoutParams(lp2);lrfoot3.setLayoutParams(lp3);



		viewLine3=findViewById(R.id.view_line3);
		viewLine3.setVisibility(View.GONE);


		//		// 隐藏与显示
		tvFollow.setVisibility(View.GONE);
		btn_help.setVisibility(View.GONE);
		btn_clearall.setVisibility(View.GONE);
		iv_up_down.setVisibility(View.GONE);
		layout_notjc.setVisibility(View.GONE);
		layout_cbs.setVisibility(View.GONE);
		btn_follow.setVisibility(View.VISIBLE);
		layout_jc.setVisibility(View.VISIBLE);

	}

	/** 初始化属性 */
	private void init() {
		App.qi = 1;
		adapter = new MyBetLotteryBJDCAdapter(Bet_BJDC_Activity.this, playtype,
				passtype);
		changeTextShow();
		initPassType();
		btn_submit.setText("付款");
		dialog = new ConfirmDialog(this, R.style.dialog);
	}

	public void initPassType() {
		if (0 == passtype) {// 过关
			if (0 != selectPasstype.size()) {
				Spanned text = Html.fromHtml(AppTools.changeStringColor(
						"#e3393c", passStr));
				tv_show_passway.setText(text);// 过关
				tv_show_passway2.setVisibility(View.GONE);
				ll_pass2.setVisibility(View.GONE);
			} else {
				Spanned text = Html.fromHtml(AppTools.changeStringColor(
						"#808080", "过关方式"));
				tv_show_passway.setText(text);// 过关
				ll_pass2.setVisibility(View.VISIBLE);
			}
			tv_show_passway.setEnabled(true);// 可用
		} else {// 单关
			passStr = "单关";
			tv_show_passway.setText(passStr);// 过关
			tv_show_passway.setTextColor(ColorUtil.BET_GRAY);
			ll_pass2.setVisibility(View.GONE);
			tv_show_passway.setEnabled(false);// 不可用
		}
	}

	/** 设置监听 */
	private void setListener() {
		btn_continue_select.setOnClickListener(this);
		bet_btn_deleteall.setOnClickListener(this);
		btn_submit.setOnClickListener(this);
		btn_follow.setOnClickListener(this);
		btn_back.setOnClickListener(this);
		bet_lv_scheme.setAdapter(adapter);
		et_bei.addTextChangedListener(bei_textWatcher);
		bet_tv_guize.setOnClickListener(this);
		tv_show_passway.setOnClickListener(this);
		layout_jc.setOnClickListener(this);
		bet_cb_stopfollow.setOnCheckedChangeListener(new MyCheckChange());
	}

	/** 复选框 **/
	class MyCheckChange implements OnCheckedChangeListener {
		@Override
		public void onCheckedChanged(CompoundButton buttonView,
				boolean isChecked) {
			if (isChecked)
				isStopChase = 1;
			else
				isStopChase = 0;
		}
	}

	/** 当文本的值改变时 */
	private TextWatcher bei_textWatcher = new TextWatcher() {
		@Override
		public void onTextChanged(CharSequence arg0, int arg1, int arg2,
				int arg3) {
		}

		@Override
		public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
				int arg3) {
		}

		@Override
		public void afterTextChanged(Editable edt) {

			if (edt.toString().trim().length() != 0) {
				if (Integer.parseInt(edt.toString().trim()) > 9999) {
					et_bei.setSelection(et_bei.getText().length());
					MyToast.getToast(getApplicationContext(), "最大倍数为9999")
							.show();
					et_bei.setText("9999");
				}
				if (Integer.parseInt(edt.toString().trim()) == 0) {
					et_bei.setText("1");
					et_bei.setSelection(et_bei.getText().length());
					MyToast.getToast(getApplicationContext(), "最小为1倍").show();
				}
				if (0 != sumCount) {
					setSelectNumAndGetCount();
				}

//				getJiangjin();
			}
			changeTextShow();
			setCursorPosition(et_bei);
		}
	};

	public void setCursorPosition(EditText et) {
		CharSequence text = et.getText();
		if (text instanceof Spannable) {
			Selection.setSelection((Spannable) text, text.length());
		}
	}

	/** 公用Button 点击监听 */
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		/** 手选 **/
		case R.id.btn_continue_select:
			btn_handClick();
			break;

		/** 返回 **/
		case R.id.btn_back:
			backToPre();
			break;

		/** 过关方式 **/
		case R.id.tv_show_passway:
		case R.id.layout_jc:
			selectPassType();
			break;

		/** 清空 **/
		case R.id.bet_btn_deleteall:
			dialog.show();
			dialog.setDialogContent("是否清空投注单号码");
			dialog.setDialogResultListener(new ConfirmDialog.DialogResultListener() {

				@Override
				public void getResult(int resultCode) {
					if (1 == resultCode) {// 确定
						ExpandAdapterbjdcPassMore.clearAllDate();
						ExpandAdapterbjdcPassSingle.clearAllDate();
						App.totalCount = 0;
						adapter.index = new HashMap<Integer, HashMap<Integer, Integer>>();
						adapter.bet_List_Matchs = new ArrayList<DtMatchBJDC>();
						adapter.setBetListMatchs();
						adapter.notifyDataSetChanged();
						selectPasstype.clear();// 清空过关方式
						initPassType();// 初始化过关方式
						changeTextShow();
					}
				}
			});
			break;
		/** 付款 **/
		case R.id.btn_submit:
			if (0 == passtype) {// 过关
				if (0 != selectPasstype.size()) {
					// if (totalMoney < 50 || App.bei < 10) {
					// MyToast.getToast(this, "北单最低不得低于10倍且不低于50元").show();
					// } else {
					setEnabled(false);
					myAsynTask = new MyAsynTask();
					myAsynTask.execute();
					// }
				} else {// 未选过关方式
					selectPassType();
				}
			} else {// 单关
			// if (totalMoney < 50 || App.bei < 10) {
			// MyToast.getToast(this, "北单最低不得低于10倍且不低于50元").show();
			// } else {
				setEnabled(false);
				myAsynTask = new MyAsynTask();
				myAsynTask.execute();
				// }
			}
			break;
		/** 发起合买 **/
		case R.id.btn_follow:
			if (0 == passtype) {// 过关
				if (0 != selectPasstype.size()) {
					join();
				} else {// 未选过关方式
					selectPassType();
				}
			} else {// 单关
				join();
			}
			break;
		case R.id.bet_tv_guize:
			Intent intent = new Intent(Bet_BJDC_Activity.this,
					PlayDescription.class);
			intent.putExtra("type", 0);
			Bet_BJDC_Activity.this.startActivity(intent);
			break;
		}
	}

	public void clearPassType() {
		selectPasstype.clear();
		initPassType();
		sumCount = 0;
		totalMoney = 0;
		changeTextShow();
	}

	private void getBonusOptimization() {
		String peilv = "";// 一种结果的赔率
		String showresult = "";
		String ret = "";
		if (null == list_JC_Details)
			list_JC_Details = new ArrayList<JC_Details>();
		else
			list_JC_Details.clear();
		int a = App.list_numbers.size();
		int b = adapter.bet_List_Matchs.size();
		for (int i = 0; i < a; i++) {
			for (int j = 0; j < b; j++) {
				String[] aa = App.list_numbers.get(i).getLotteryNumber()
						.split(";")[1].replace("|", "&").split("&");
				for (int k = 0; k < aa.length; k++) {
					String bb = aa[k].replace("[", "").replace("]", "")
							.replace(" ", "");
					if (bb.substring(0, bb.lastIndexOf("(")).equals(
							adapter.bet_List_Matchs.get(j).getMatchId())) {
						String[] jieguo = bb
								.substring(bb.lastIndexOf("("),
										bb.lastIndexOf(")")).replace("(", "")
								.replace(")", "").split(",");
						for (int k2 = 0; k2 < jieguo.length; k2++) {
							String saiguo = jieguo[k2];

							System.out.println("===rrrrrr======="
									+ App.list_numbers.get(i)
											.getLotteryNumber());

							if (App.list_numbers.get(i).getLotteryNumber()
									.split(";")[0].equals("4501")) {

								switch (Integer.parseInt(saiguo)) {
								case 1:
									peilv = adapter.bet_List_Matchs.get(j)
											.getSpfwin();
									showresult = "胜";
									break;
								case 2:
									peilv = adapter.bet_List_Matchs.get(j)
											.getSpfflat();
									showresult = "平";
									break;
								case 3:
									peilv = adapter.bet_List_Matchs.get(j)
											.getSpflose();
									showresult = "负";
									break;
								default:
									break;
								}
							}

							if (App.list_numbers.get(i).getLotteryNumber()
									.split(";")[0].equals("4502")) {
								switch (Integer.parseInt(saiguo)) {
								case 1:
									peilv = adapter.bet_List_Matchs.get(j)
											.getIn0();
									showresult = "0";
									break;
								case 2:
									peilv = adapter.bet_List_Matchs.get(j)
											.getIn1();
									showresult = "1";
									break;
								case 3:
									peilv = adapter.bet_List_Matchs.get(j)
											.getIn2();
									showresult = "2";
									break;
								case 4:
									peilv = adapter.bet_List_Matchs.get(j)
											.getIn3();
									showresult = "3";
									break;
								case 5:
									peilv = adapter.bet_List_Matchs.get(j)
											.getIn4();
									showresult = "4";
									break;
								case 6:
									peilv = adapter.bet_List_Matchs.get(j)
											.getIn5();
									showresult = "5";
									break;
								case 7:
									peilv = adapter.bet_List_Matchs.get(j)
											.getIn6();
									showresult = "6";
									break;
								case 8:
									peilv = adapter.bet_List_Matchs.get(j)
											.getIn7();
									showresult = "7+";
									break;
								default:
									break;
								}
							}
							if (App.list_numbers.get(i).getLotteryNumber()
									.split(";")[0].equals("4503")) {
								System.out.println("=======saiguo======"
										+ saiguo);
								switch (Integer.parseInt(saiguo)) {
								case 1:
									peilv = adapter.bet_List_Matchs.get(j)
											.getUpdan();
									showresult = "上单";
									System.out.println(showresult + "==="
											+ peilv);
									break;
								case 2:
									peilv = adapter.bet_List_Matchs.get(j)
											.getUpshuang();
									showresult = "上双";
									break;
								case 3:
									peilv = adapter.bet_List_Matchs.get(j)
											.getDowndan();
									showresult = "下单";
									break;
								case 4:
									peilv = adapter.bet_List_Matchs.get(j)
											.getDownshuang();
									showresult = "下双";
									break;
								default:
									break;
								}
							}

							if (App.list_numbers.get(i).getLotteryNumber()
									.split(";")[0].equals("4504")) {
								System.out.println("=======saiguo======"
										+ saiguo);
								switch (Integer.parseInt(saiguo)) {
								case 1:
									peilv = adapter.bet_List_Matchs.get(j)
											.getS10();
									showresult = "1:0";

									break;
								case 2:
									peilv = adapter.bet_List_Matchs.get(j)
											.getS20();
									showresult = "2:0";
									break;
								case 3:
									peilv = adapter.bet_List_Matchs.get(j)
											.getS21();
									showresult = "2:1";
									break;
								case 4:
									peilv = adapter.bet_List_Matchs.get(j)
											.getS30();
									showresult = "3:0";
									break;
								case 5:
									peilv = adapter.bet_List_Matchs.get(j)
											.getS31();
									showresult = "3:1";
									break;
								case 6:
									peilv = adapter.bet_List_Matchs.get(j)
											.getS32();
									showresult = "3:2";
									break;
								case 7:
									peilv = adapter.bet_List_Matchs.get(j)
											.getS40();
									showresult = "4:0";
									break;
								case 8:
									peilv = adapter.bet_List_Matchs.get(j)
											.getS41();
									showresult = "4:1";
									break;
								case 9:
									peilv = adapter.bet_List_Matchs.get(j)
											.getS42();
									showresult = "4:2";

									break;
								case 10:
									peilv = adapter.bet_List_Matchs.get(j)
											.getSother();
									showresult = "胜其他";
									break;

								case 11:
									peilv = adapter.bet_List_Matchs.get(j)
											.getP00();
									showresult = "0:0";
									break;
								case 12:
									peilv = adapter.bet_List_Matchs.get(j)
											.getP11();
									showresult = "1:1";
									break;
								case 13:
									peilv = adapter.bet_List_Matchs.get(j)
											.getP22();
									showresult = "2:2";
									break;
								case 14:
									peilv = adapter.bet_List_Matchs.get(j)
											.getP33();
									showresult = "3:3";
									break;
								case 15:
									peilv = adapter.bet_List_Matchs.get(j)
											.getPother();
									showresult = "平其他";
									break;
								case 16:
									peilv = adapter.bet_List_Matchs.get(j)
											.getF01();
									showresult = "0:1";
									break;
								case 17:
									peilv = adapter.bet_List_Matchs.get(j)
											.getF02();
									showresult = "0:2";
									break;
								case 18:
									peilv = adapter.bet_List_Matchs.get(j)
											.getF12();
									showresult = "1:2";
									break;
								case 19:
									peilv = adapter.bet_List_Matchs.get(j)
											.getF03();
									showresult = "0:3";
									break;
								case 20:
									peilv = adapter.bet_List_Matchs.get(j)
											.getF13();
									showresult = "1:3";
									break;
								case 21:
									peilv = adapter.bet_List_Matchs.get(j)
											.getF23();
									showresult = "2:3";
									break;
								case 22:
									peilv = adapter.bet_List_Matchs.get(j)
											.getF04();
									showresult = "0:4";
									break;
								case 23:
									peilv = adapter.bet_List_Matchs.get(j)
											.getF14();
									showresult = "1:4";
									break;

								case 24:
									peilv = adapter.bet_List_Matchs.get(j)
											.getF24();
									showresult = "2:4";
									break;

								case 25:
									peilv = adapter.bet_List_Matchs.get(j)
											.getFother();
									showresult = "负其他";
									break;

								default:
									break;

								}
							}

							if (App.list_numbers.get(i).getLotteryNumber()
									.split(";")[0].equals("4505")) {
								switch (Integer.parseInt(saiguo)) {
								case 1:
									peilv = adapter.bet_List_Matchs.get(j)
											.getSs();
									showresult = "胜胜";

									break;
								case 2:
									peilv = adapter.bet_List_Matchs.get(j)
											.getSp();
									showresult = "胜平";
									break;
								case 3:
									peilv = adapter.bet_List_Matchs.get(j)
											.getSf();
									showresult = "胜负";
									break;
								case 4:
									peilv = adapter.bet_List_Matchs.get(j)
											.getPs();
									showresult = "平胜";
									break;
								case 5:
									peilv = adapter.bet_List_Matchs.get(j)
											.getPp();
									showresult = "平平";
									break;
								case 6:
									peilv = adapter.bet_List_Matchs.get(j)
											.getPf();
									showresult = "平负";
									break;
								case 7:
									peilv = adapter.bet_List_Matchs.get(j)
											.getFs();
									showresult = "负胜";
									break;
								case 8:
									peilv = adapter.bet_List_Matchs.get(j)
											.getFp();
									showresult = "负平";
									break;
								case 9:
									peilv = adapter.bet_List_Matchs.get(j)
											.getFf();
									showresult = "负负";
									break;
								default:
									break;
								}
								System.out.println(showresult + "====" + peilv);
							}

							JC_Details jc_details = new JC_Details();
							jc_details.setPlaytype_info(App.list_numbers
									.get(i).getLotteryNumber().split(";")[0]);
							jc_details.setMatchNumber(adapter.bet_List_Matchs
									.get(j).getMatchNumber());
							jc_details.setResult(saiguo);
							jc_details.setMatchID(adapter.bet_List_Matchs
									.get(j).getMatchId());

							jc_details.setMainTeam(adapter.bet_List_Matchs.get(
									j).getMainTeam());
							jc_details.setGuestTeam(adapter.bet_List_Matchs
									.get(j).getGuestTeam());
							jc_details.setShowresult(showresult);
							jc_details.setPeilv(Double.parseDouble(peilv
									.equals("") ? "0" : peilv));
							list_JC_Details.add(jc_details);
						}
					}
				}
			}
		}

	}

	/**
	 * 选择过关方式
	 */
	public void selectPassType() {
		HashMap<Integer, HashMap<Integer, ArrayList<String>>> map_hashMap = new HashMap<Integer, HashMap<Integer, ArrayList<String>>>();
		if (0 == passtype) {// 过关
			switch (playtype) {// 获取选中的map信息
			case 1:// 胜平负
				map_hashMap = ExpandAdapterbjdcPassMore.map_hashMap_spf;
				break;
			case 2:// 总进球
				map_hashMap = ExpandAdapterbjdcPassMore.map_hashMap_zjq;
				break;
			case 3:// 上下单双
				map_hashMap = ExpandAdapterbjdcPassMore.map_hashMap_sxds;
				break;
			case 4:// 比分
				map_hashMap = ExpandAdapterbjdcPassMore.map_hashMap_cbf;
				break;
			case 5:// 半全场
				map_hashMap = ExpandAdapterbjdcPassMore.map_hashMap_bqc;
				break;
			case 6:// 半全场
				map_hashMap = ExpandAdapterbjdcPassMore.map_hashMap_sfgg;
				break;
			}
		}
		countDan = adapter.selectDanCount;// 胆的个数
		dtCount = adapter.getSelectDtMatchCount(map_hashMap);// 获取已选择的比赛场次
		if (playtype == 6) {
			if (passType_list.getVisibility() == View.GONE) {
				passType_list.setVisibility(View.VISIBLE);
				tv_show_passway.setVisibility(View.GONE);
				tv_show_passway2.setVisibility(View.GONE);
				tv_show_passway3.setVisibility(View.VISIBLE);

				listAdapter_sf = new SelectPasstype_List_BJDCSFAdapter(
						getApplicationContext(), countDan, dtCount,
						viewPagerCurrentIndex);
				passType_list.setAdapter(listAdapter_sf);
				listAdapter_sf.notifyDataSetChanged();
			} else {
				if (tv_show_passway.getText().toString().trim().equals("过关方式")) {
					tv_show_passway2.setVisibility(View.VISIBLE);
					ll_pass2.setVisibility(View.VISIBLE);
				} else {
					tv_show_passway2.setVisibility(View.GONE);
					ll_pass2.setVisibility(View.GONE);
				}
				passType_list.setVisibility(View.GONE);
				tv_show_passway.setVisibility(View.VISIBLE);
				tv_show_passway3.setVisibility(View.GONE);
			}

			// selectPTpopsf = new SelectBjdcsfPassTypePopupWindow(
			// getApplicationContext(), countDan, dtCount,
			// viewPagerCurrentIndex, layout_main);
			if (0 != selectPasstype.size()) {// 不为空
				listAdapter_sf.setSelectPassType(selectPasstype);
			} else {
				listAdapter_sf.setSelectPassType(new ArrayList<String>());
			}
			// selectPTpopsf.createPopWindow();
			listAdapter_sf
					.setDialogResultListener(new SelectPasstype_List_BJDCSFAdapter.DialogResultListener() {
						@Override
						public void getResult(int resultCode,
								ArrayList<String> selectResult, int type) {
							// TODO Auto-generated method stub
							if (1 == resultCode) {// 确定
								viewPagerCurrentIndex = type;
								selectPasstype = selectResult;
								if (0 != selectPasstype.size()) {// 不为空
									StringBuffer show = new StringBuffer();
									for (int i = 0; i < selectPasstype.size(); i++) {
										HashMap<String, String> passtypeMap = listAdapter_sf
												.getPASSTYPE_MAP();
										show.append(","
												+ passtypeMap
														.get(selectPasstype
																.get(i)));
									}
									passStr = show.substring(1);
									if (null != passStr && !"".equals(passStr)) {
										Spanned text = Html.fromHtml(AppTools
												.changeStringColor("#e3393c",
														passStr));
										tv_show_passway.setText(text);// 过关
										tv_show_passway2
												.setVisibility(View.GONE);
										ll_pass2.setVisibility(View.GONE);
									} else {
										Spanned text = Html.fromHtml(AppTools
												.changeStringColor("#808080",
														"过关方式"));
										tv_show_passway.setText(text);// 过关
										ll_pass2.setVisibility(View.VISIBLE);
									}
									// tv_show_passway.setText(passStr);// 过关
									// tv_show_passway.setTextColor(Color.WHITE);
									// tv_show_passway
									// .setBackgroundResource(R.drawable.select_jc_bg_red);//
									// 设置背景
									setSelectNumAndGetCount();// 设置投注格式,计算注数
									changeTextShow();
								} else {
									sumCount = 0;
									changeTextShow();
									initPassType();
								}
							}
						}
					});
		} else {
			if (passType_list.getVisibility() == View.GONE) {
				passType_list.setVisibility(View.VISIBLE);
				tv_show_passway.setVisibility(View.GONE);
				tv_show_passway2.setVisibility(View.GONE);
				tv_show_passway3.setVisibility(View.VISIBLE);

				listAdapter = new SelectPasstype_List_BJDCAdapter(
						getApplicationContext(), countDan, dtCount,
						viewPagerCurrentIndex, playtype);
				passType_list.setAdapter(listAdapter);
				listAdapter.notifyDataSetChanged();
			} else {
				passType_list.setVisibility(View.GONE);
				tv_show_passway.setVisibility(View.VISIBLE);
				// tv_show_passway2.setVisibility(View.VISIBLE);
				if (tv_show_passway.getText().toString().trim().equals("过关方式")) {
					tv_show_passway2.setVisibility(View.VISIBLE);
					ll_pass2.setVisibility(View.VISIBLE);
				} else {
					tv_show_passway2.setVisibility(View.GONE);
					ll_pass2.setVisibility(View.GONE);
				}
				tv_show_passway3.setVisibility(View.GONE);
			}
			// selectPTpop = new SelectBjdcPassTypePopupWindow(
			// getApplicationContext(), countDan, dtCount,
			// viewPagerCurrentIndex, layout_main, playtype);
			if (0 != selectPasstype.size()) {// 不为空
				listAdapter.setSelectPassType(selectPasstype);
			} else {
				listAdapter.setSelectPassType(new ArrayList<String>());
			}
			// selectPTpop.createPopWindow();
			listAdapter
					.setDialogResultListener(new SelectPasstype_List_BJDCAdapter.DialogResultListener() {
						@Override
						public void getResult(int resultCode,
								ArrayList<String> selectResult, int type) {
							if (1 == resultCode) {// 确定
								viewPagerCurrentIndex = type;
								selectPasstype = selectResult;
								if (0 != selectPasstype.size()) {// 不为空
									StringBuffer show = new StringBuffer();
									for (int i = 0; i < selectPasstype.size(); i++) {
										HashMap<String, String> passtypeMap = listAdapter
												.getPASSTYPE_MAP();
										show.append(","
												+ passtypeMap
														.get(selectPasstype
																.get(i)));
									}
									passStr = show.substring(1);
									if (null != passStr && !"".equals(passStr)) {
										Spanned text = Html.fromHtml(AppTools
												.changeStringColor("#e3393c",
														passStr));
										tv_show_passway.setText(text);// 过关
										tv_show_passway2
												.setVisibility(View.GONE);
										ll_pass2.setVisibility(View.GONE);
									} else {
										Spanned text = Html.fromHtml(AppTools
												.changeStringColor("#808080",
														"过关方式"));
										tv_show_passway.setText(text);// 过关
										ll_pass2.setVisibility(View.VISIBLE);
									}
									// tv_show_passway.setText(passStr);// 过关
									// tv_show_passway.setTextColor(Color.WHITE);
									setSelectNumAndGetCount();// 设置投注格式,计算注数
									changeTextShow();
									getJiangjin();
								} else {
									sumCount = 0;
									layout_tip_jiangjin
											.setVisibility(View.GONE);
									changeTextShow();
									initPassType();
								}
							}
						}
					});
		}
	}

	private void getJiangjin() {
		getBonusOptimization();
		get_max_peilv_list();
		get_min_peilv_list();
		max_jiangjin = JiangjinTools.getbjdc_jiangjin("max", passStr,
				list_max_jiangjin);
		min_jiangjin = JiangjinTools.getbjdc_jiangjin("min", passStr,
				list_min_jiangjin);
		System.out.println("=======max_jiangjin====" + max_jiangjin);
		System.out.println("=======min_jiangjin====" + min_jiangjin);

		if (max_jiangjin > 0) {
			layout_tip_jiangjin.setVisibility(View.VISIBLE);
			if (max_jiangjin == min_jiangjin) {
				tv_jiangjin.setText((int) (max_jiangjin * App.bei) + "");

			} else {
				tv_jiangjin.setText((int) (min_jiangjin * App.bei) + "~" + (int) (max_jiangjin * App.bei));
			}
		} else {
			layout_tip_jiangjin.setVisibility(View.GONE);
		}
	}

	// 得到没场对阵的最小赔率
	private void get_min_peilv_list() {
		for (int i = 0; i < Bet_BJDC_Activity.list_JC_Details.size(); i++) {
			if (min_peilv.containsKey(Bet_BJDC_Activity.list_JC_Details.get(i)
					.getMatchID())) {
				if (Double.parseDouble(Bet_BJDC_Activity.list_JC_Details.get(i)
						.getPeilv()) < Double.parseDouble(min_peilv
						.get(Bet_BJDC_Activity.list_JC_Details.get(i)
								.getMatchID()))) {
					min_peilv.put(Bet_BJDC_Activity.list_JC_Details.get(i)
							.getMatchID(), Bet_BJDC_Activity.list_JC_Details
							.get(i).getPeilv());
				} else
					continue;
			} else
				min_peilv.put(Bet_BJDC_Activity.list_JC_Details.get(i)
						.getMatchID(), Bet_BJDC_Activity.list_JC_Details.get(i)
						.getPeilv());
		}

		if (list_min_jiangjin.size() > 0) {
			list_min_jiangjin.clear();
		}
		Iterator iter = min_peilv.entrySet().iterator();
		while (iter.hasNext()) {
			Map.Entry entry = (Map.Entry) iter.next();
			String val = (String) entry.getValue();
			list_min_jiangjin.add(Double.parseDouble(val));
		}

	}

	// 得到没场对阵的最大赔率
	private void get_max_peilv_list() {
		for (int i = 0; i < Bet_BJDC_Activity.list_JC_Details.size(); i++) {
			if (max_peilv.containsKey(Bet_BJDC_Activity.list_JC_Details.get(i)
					.getMatchID())) {
				if (Double.parseDouble(Bet_BJDC_Activity.list_JC_Details.get(i)
						.getPeilv()) > Double.parseDouble(max_peilv
						.get(Bet_BJDC_Activity.list_JC_Details.get(i)
								.getMatchID()))) {
					max_peilv.put(Bet_BJDC_Activity.list_JC_Details.get(i)
							.getMatchID(), Bet_BJDC_Activity.list_JC_Details
							.get(i).getPeilv());
				} else
					continue;
			} else
				max_peilv.put(Bet_BJDC_Activity.list_JC_Details.get(i)
						.getMatchID(), Bet_BJDC_Activity.list_JC_Details.get(i)
						.getPeilv());
		}
		if (list_max_jiangjin.size() > 0) {
			list_max_jiangjin.clear();
		}
		Iterator iter = max_peilv.entrySet().iterator();
		while (iter.hasNext()) {
			Map.Entry entry = (Map.Entry) iter.next();
			String val = (String) entry.getValue();
			list_max_jiangjin.add(Double.parseDouble(val));
		}
	}

	public void setSelectNumAndGetCount() {
		sumCount = 0;
		eachSelectDT = new ArrayList<String>();
		List<String> dan_list = new ArrayList<String>();// 存放胆的集合
		StringBuffer sb = new StringBuffer();
		int playType = 0;
		switch (playtype) {
		case 1:// 胜平负
			playType = 4501;
			break;
		case 2:// 总进球
			playType = 4502;
			break;
		case 3:// 上下单双
			playType = 4503;
			break;
		case 4:// 比分
			playType = 4504;
			break;
		case 5:// 半全场
			playType = 4505;
			break;
		case 6:// 半全场
			playType = 4506;
			break;
		}

		sb.append(playType + ";");
		StringBuffer notdan_sb = new StringBuffer();// 用来拼接
		StringBuffer dan_sb = new StringBuffer();// 用来拼接
		if (0 == passtype) {// 过关
			sb.append("[");
			for (int i = 0; i < ExpandAdapterbjdcPassMore.list_Matchs.size(); i++) {// 遍历过关所有对阵
				HashMap<Integer, HashMap<Integer, ArrayList<String>>> map_hashMap = new HashMap<Integer, HashMap<Integer, ArrayList<String>>>();
				switch (playtype) {// 获取选中的map信息
				case 1:// 胜平负
					map_hashMap = ExpandAdapterbjdcPassMore.map_hashMap_spf;
					break;
				case 2:// 总进球
					map_hashMap = ExpandAdapterbjdcPassMore.map_hashMap_zjq;
					break;
				case 3:// 上下单双
					map_hashMap = ExpandAdapterbjdcPassMore.map_hashMap_sxds;
					break;
				case 4:// 比分
					map_hashMap = ExpandAdapterbjdcPassMore.map_hashMap_cbf;
					break;
				case 5:// 半全场
					map_hashMap = ExpandAdapterbjdcPassMore.map_hashMap_bqc;
					break;
				case 6:// 半全场
					map_hashMap = ExpandAdapterbjdcPassMore.map_hashMap_sfgg;
					break;
				}
				// 拼接投注格式
				if (map_hashMap.containsKey(i)) {// 包含父下标
					HashMap<Integer, Integer> cids = new HashMap<Integer, Integer>();
					Map<Integer, ArrayList<String>> map = map_hashMap.get(i);
					Set<Integer> cset = map.keySet();
					int cursor = 0;
					if (0 == countDan) {// 没有设胆
						for (Integer cid : cset) {// 遍历已选每一个对阵
							DtMatchBJDC dm = ExpandAdapterbjdcPassMore.list_Matchs
									.get(i).get(cid);
							ArrayList<String> selectNum = map.get(cid);// 一场比赛选的结果
							StringBuffer each = new StringBuffer();
							sb.append(dm.getMatchId() + "(");
							// 用于混合投注拼接特殊字符串计算注数
							StringBuffer each1 = new StringBuffer();
							StringBuffer each2 = new StringBuffer();
							StringBuffer each3 = new StringBuffer();
							StringBuffer each4 = new StringBuffer();
							StringBuffer each5 = new StringBuffer();
							StringBuffer each6 = new StringBuffer();
							for (int j = 0; j < selectNum.size(); j++) {
								String str = selectNum.get(j);

								each.append("1");
								for (int n = 101; n <= 103; n++) {// 胜平负
									if (str.contains(n + "")) {// 如果包含则替换
										String old = n + "";
										str = str
												.replace(old, old.substring(
														old.length() - 1,
														old.length()));
									}
								}
								for (int h = 201; h <= 208; h++) {// 总进球数
									if (str.contains(h + "")) {// 如果包含则替换
										String old = h + "";
										str = str
												.replace(old, old.substring(
														old.length() - 1,
														old.length()));
									}
								}
								for (int k = 301; k <= 331; k++) {// 比分
									if (str.contains(k + "")) {// 如果包含则替换
										String old = k + "";
										if (k < 310) {
											str = str.replace(old, old
													.substring(
															old.length() - 1,
															old.length()));
										} else {
											str = str.replace(old, old
													.substring(
															old.length() - 2,
															old.length()));
										}
									}
								}
								for (int l = 401; l <= 409; l++) {// 半全场
									if (str.contains(l + "")) {// 如果包含则替换
										String old = l + "";
										str = str
												.replace(old, old.substring(
														old.length() - 1,
														old.length()));
									}
								}
								for (int m = 701; m <= 704; m++) {// 让球胜平负
									if (str.contains(m + "")) {// 如果包含则替换
										String old = m + "";
										str = str
												.replace(old, old.substring(
														old.length() - 1,
														old.length()));
									}
								}
								if (str.contains(603 + "")) {
									String old = 603 + "";
									str = str.replace(
											old,
											old.substring(old.length() - 1,
													old.length()));
								} else if (str.contains(601 + "")) {
									String old = 601 + "";
									str = str.replace(
											old,
											old.substring(old.length() - 1,
													old.length()));
								}

								if (0 == j) {
									sb.append(str);
								} else {
									sb.append("," + str);
								}
							}
							if (0 != each1.length()) {// 胜平负
								String str1 = "";
								if (0 == each2.length() && 0 == each3.length()
										&& 0 == each4.length()
										&& 0 == each5.length()
										&& 0 == each6.length()) {// 只有胜平负
									str1 = each1.substring(0,
											each1.length() - 1);
								} else {
									str1 = each1.substring(0,
											each1.length() - 1) + "|";
								}
								each.append(str1);
							}
							if (0 != each2.length()) {// 总进球数
								String str2 = "";
								if (0 == each3.length() && 0 == each4.length()
										&& 0 == each5.length()
										&& 0 == each6.length()) {// 没有比分，半全场，让球胜平负
									str2 = each2.substring(0,
											each2.length() - 1);
								} else {
									str2 = each2.substring(0,
											each2.length() - 1) + "|";
								}
								each.append(str2);
							}
							if (0 != each3.length()) {// 比分
								String str3 = "";
								if (0 == each4.length() && 0 == each5.length()
										&& 0 == each6.length()) {// 没有半全场，让球胜平负
									str3 = each3.substring(0,
											each3.length() - 1);
								} else {
									str3 = each3.substring(0,
											each3.length() - 1) + "|";
								}
								each.append(str3);
							}
							if (0 != each4.length()) {// 半全场
								String str4 = "";
								if (0 == each5.length() && 0 == each6.length()) {// 没有半全场，让球胜平负
									str4 = each4.substring(0,
											each4.length() - 1);
								} else {
									str4 = each4.substring(0,
											each4.length() - 1) + "|";
								}
								each.append(str4);
							}
							if (0 != each5.length()) {// 半全场
								String str5 = "";
								if (0 == each6.length()) {// 没有半全场，让球胜平负
									str5 = each5.substring(0,
											each5.length() - 1);
								} else {
									str5 = each5.substring(0,
											each5.length() - 1) + "|";
								}
								each.append(str5);
							}
							if (0 != each6.length()) {
								String str6 = each6.substring(0,
										each6.length() - 1);
								each.append(str6);
							}
							if (4508 == playType)
								Log.i(TAG, "混合投注拼接字符串" + each);
							eachSelectDT.add(each.toString());// 添加每一场对阵选的结果
							sb.append(")|");
						}
					} else {// 已设胆
						for (Integer cid : cset) {// 遍历已选每一个对阵
							DtMatchBJDC dm = ExpandAdapterbjdcPassMore.list_Matchs
									.get(i).get(cid);
							ArrayList<String> selectNum = map.get(cid);
							if (selectNum.contains("1")) {// 选胆了
								dan_sb.append(dm.getMatchId() + "(");
								StringBuffer dan_sb_list = new StringBuffer();// 加入danlist
								for (int j = 0; j < selectNum.size(); j++) {// 一场对阵
									String str = selectNum.get(j);// 对阵的一个结果
									if (!"1".equals(str)) {// 非胆
										for (int n = 101; n <= 103; n++) {// 胜平负
											if (str.contains(n + "")) {// 如果包含则替换
												String old = n + "";
												str = str
														.replace(
																old,
																old.substring(
																		old.length() - 1,
																		old.length()));
											}
										}
										for (int h = 201; h <= 208; h++) {// 总进球数
											if (str.contains(h + "")) {// 如果包含则替换
												String old = h + "";
												str = str
														.replace(
																old,
																old.substring(
																		old.length() - 1,
																		old.length()));
											}
										}
										for (int k = 301; k <= 331; k++) {// 比方
											if (str.contains(k + "")) {// 如果包含则替换
												String old = k + "";
												if (k < 310) {
													str = str
															.replace(
																	old,
																	old.substring(
																			old.length() - 1,
																			old.length()));
												} else {
													str = str
															.replace(
																	old,
																	old.substring(
																			old.length() - 2,
																			old.length()));
												}
											}
										}
										for (int l = 401; l <= 409; l++) {// 半全场
											if (str.contains(l + "")) {// 如果包含则替换
												String old = l + "";
												str = str
														.replace(
																old,
																old.substring(
																		old.length() - 1,
																		old.length()));
											}
										}
										for (int m = 701; m <= 704; m++) {// 让球胜平负
											if (str.contains(m + "")) {// 如果包含则替换
												String old = m + "";
												str = str
														.replace(
																old,
																old.substring(
																		old.length() - 1,
																		old.length()));
											}
										}
										if (str.contains(603 + "")) {
											String old = 603 + "";
											str = str.replace(old, old
													.substring(
															old.length() - 1,
															old.length()));
										} else if (str.contains(601 + "")) {
											String old = 601 + "";
											str = str.replace(old, old
													.substring(
															old.length() - 1,
															old.length()));
										}
										dan_sb_list.append("1");// 将每一个结果拼接
										if (0 == j) {
											dan_sb.append(str);
										} else {
											dan_sb.append("," + str);
										}
									}
								}
								dan_sb.append(")|");// 一场比赛的所有结果
								dan_list.add(dan_sb_list.toString());// 将拼接的所选胆的结果放入集合dan_list
							} else {// 未选胆的
								notdan_sb.append(dm.getMatchId() + "(");
								StringBuffer notdan_sb_list = new StringBuffer();// 加入list
								for (int j = 0; j < selectNum.size(); j++) {// 一场对阵
									String str = selectNum.get(j);// 对阵的一个结果

									for (int n = 101; n <= 103; n++) {// 胜平负
										if (str.contains(n + "")) {// 如果包含则替换
											String old = n + "";
											str = str.replace(old, old
													.substring(
															old.length() - 1,
															old.length()));
										}
									}
									for (int h = 201; h <= 208; h++) {// 总进球数
										if (str.contains(h + "")) {// 如果包含则替换
											String old = h + "";
											str = str.replace(old, old
													.substring(
															old.length() - 1,
															old.length()));
										}
									}
									for (int k = 301; k <= 331; k++) {// 比分
										if (str.contains(k + "")) {// 如果包含则替换
											String old = k + "";
											if (k < 310) {
												str = str
														.replace(
																old,
																old.substring(
																		old.length() - 1,
																		old.length()));
											} else {
												str = str
														.replace(
																old,
																old.substring(
																		old.length() - 2,
																		old.length()));
											}
										}
									}
									for (int l = 401; l <= 409; l++) {// 半全场
										if (str.contains(l + "")) {// 如果包含则替换
											String old = l + "";
											str = str.replace(old, old
													.substring(
															old.length() - 1,
															old.length()));
										}
									}
									for (int m = 701; m <= 704; m++) {// 让球胜平负
										if (str.contains(m + "")) {// 如果包含则替换
											String old = m + "";
											str = str.replace(old, old
													.substring(
															old.length() - 1,
															old.length()));
										}
									}
									if (str.contains(603 + "")) {
										String old = 603 + "";
										str = str
												.replace(old, old.substring(
														old.length() - 1,
														old.length()));
									} else if (str.contains(600 + "")) {
										String old = 600 + "";
										str = str
												.replace(old, old.substring(
														old.length() - 1,
														old.length()));
									}
									notdan_sb_list.append("1");// 将每一个结果拼接
									if (0 == j) {
										notdan_sb.append(str);
									} else {
										notdan_sb.append("," + str);
									}
								}
								notdan_sb.append(")|");// 一场比赛的所有结果
								eachSelectDT.add(notdan_sb_list.toString());// 将拼接的所选胆的结果放入集合dan_list
							}
						}
					}
				}
			}
			if (0 != dan_sb.length() && 0 != notdan_sb.length()) {
				String dan = dan_sb.toString();
				dan = dan_sb.substring(0, dan_sb.length() - 1);// 去除最后一个“|”
				sb.append(dan + "][");// 加胆右边中括号和非胆左中括号
				String notdan = notdan_sb.toString();// 去除最后一个“|”
				sb.append(notdan);
			}
			sb = new StringBuffer(sb.substring(0, sb.length() - 1));// 去掉“|”
			sb.append("]");
		}
		StringBuffer passtype = new StringBuffer();
		for (int i = 0; i < selectPasstype.size(); i++) {
			if (0 == i) {
				passtype.append(selectPasstype.get(i) + App.bei);
			} else {

				passtype.append("," + selectPasstype.get(i) + App.bei);
			}
		}
		if (1 == this.passtype) {// 单关
			passtype.append("A0" + App.bei);
		}
		String str = "";
		if (0 != countDan) {// 含胆
			str = sb.toString() + ";[" + passtype + "];[" + countDan + "]";// 拼接成lotteryNumber
		} else {
			str = sb.toString() + ";[" + passtype + "]";// 拼接成lotteryNumber
		}
		App.list_numbers = new ArrayList<SelectedNumbers>();
		SelectedNumbers selectNumber = new SelectedNumbers();
		selectNumber.setPlayType(playType);// 设置玩法类型
		selectNumber.setLotteryNumber(str);// 设置投注号码
		StringBuffer selectpass = new StringBuffer();

		for (int i = 0; i < selectPasstype.size(); i++) {
			if (0 == i) {
				selectpass.append(selectPasstype.get(i));
			} else {
				selectpass.append(" " + selectPasstype.get(i));
			}
		}
		if (1 == this.passtype) {// 单关
			selectpass.append(passtype.toString());
		}
		// 计算注数
		if (0 == countDan) {// 无胆
			setTotalCount(selectpass.toString(), eachSelectDT);
		} else {// 有胆
			setTotalCount(selectpass.toString(), dan_list, eachSelectDT);
		}
		selectNumber.setCount(sumCount);// 设置投注注数
		totalMoney = sumCount * 2 * App.bei;
		selectNumber.setMoney(sumCount * 2);// 设置投注钱数
		App.list_numbers.add(selectNumber);
	}

	/** 设置是否可用 **/
	private void setEnabled(boolean isEna) {
		btn_submit.setEnabled(isEna);
		bet_btn_deleteall.setEnabled(isEna);
		btn_continue_select.setEnabled(isEna);
		btn_follow.setEnabled(isEna);
		bet_cb_stopfollow.setEnabled(isEna);
		et_bei.setEnabled(isEna);
	}

	/** 跳到合买 */
	private void join() {
		if (App.qi > 1) {
			dialog.show();
			dialog.setDialogContent("发起合买时不能追号，是否只追一期并继续发起合买？");
			dialog.setDialogResultListener(new ConfirmDialog.DialogResultListener() {

				@Override
				public void getResult(int resultCode) {
					// TODO Auto-generated method stub
					if (1 == resultCode) {// 确定
						App.qi = 1;
						int total = 0; // 总金额
						for (SelectedNumbers num : App.list_numbers) {
							total += num.getMoney();
						}
						total = total * App.bei;
						intent = new Intent(Bet_BJDC_Activity.this,
								JoinActivity.class);
						intent.putExtra("totalMoney", total + "");
						Bet_BJDC_Activity.this.startActivity(intent);
					}
				}
			});
		} else {
			int total = 0; // 总金额
			for (SelectedNumbers num : App.list_numbers) {
				total += num.getMoney();
			}
			if (total == 0) {
				MyToast.getToast(getApplicationContext(), "您还没有选择场次").show();
				return;
			}
			total = total * App.bei;
			intent = new Intent(Bet_BJDC_Activity.this, JoinActivity.class);
			intent.putExtra("totalMoney", total + "");
			Bet_BJDC_Activity.this.startActivity(intent);
		}
	}

	/** 手选按钮点击事件 */
	private void btn_handClick() {
		App.totalCount = 0;
		Intent intent = new Intent(Bet_BJDC_Activity.this,
				Select_bjdcActivity.class);
		intent.putExtra("passtype", passtype);
		int playType = 4501;
		switch (playtype) {
		case 1:// 胜平负
			playType = 4501;
			break;
		case 2:// 总进球
			playType = 4502;
			break;
		case 3:// 上下单双
			playType = 4503;
			break;
		case 4:// 比分
			playType = 4504;
			break;
		case 5:// 半全场
			playType = 4505;
			break;
		case 6:// 半全场
			playType = 4506;
			break;
		}
		intent.putExtra("playtype", playType);
		Bet_BJDC_Activity.this.startActivity(intent);
		Bet_BJDC_Activity.this.finish();
	}

	/** 改变文本的值显示出来 */
	public void changeTextShow() {

		tv_tatol_count.setText(sumCount + "");// 总注数
		String str = et_bei.getText() + "";

		if(str.equals("")){

			App.bei=1;

		}else{
			App.bei = Integer.parseInt(str);

		}

		if (max_jiangjin > 0) {
			layout_tip_jiangjin.setVisibility(View.VISIBLE);
			if (max_jiangjin == min_jiangjin) {
				tv_jiangjin.setText((int) (max_jiangjin * App.bei) + "");

			} else {
				tv_jiangjin.setText((int) (min_jiangjin * App.bei) + "~" + (int) (max_jiangjin * App.bei));
			}
		} else {
			layout_tip_jiangjin.setVisibility(View.GONE);
		}
		totalMoney = sumCount * 2 * App.bei;
		tv_tatol_money.setText(totalMoney + "");// 总钱数
	}

	/**
	 * 返回
	 */
	public void backToPre() {
		if (!Select_bjdcActivity.isEmptJCZQ()) {
			dialog.show();
			dialog.setDialogContent("您退出后选择场次将会清空！");
			dialog.setDialogResultListener(new ConfirmDialog.DialogResultListener() {

				@Override
				public void getResult(int resultCode) {
					// TODO Auto-generated method stub
					if (1 == resultCode) {
						ExpandAdapterbjdcPassMore.clearAllDate();
						ExpandAdapterbjdcPassSingle.clearAllDate();
						App.totalCount = 0;
						Select_bjdcActivity.clearAllData();
						for (int i = 0; i < App.activityS1.size(); i++) {
							App.activityS1.get(i).finish();
						} 
					}
				}
			});
		} else {
			ExpandAdapterbjdcPassMore.clearAllDate();
			ExpandAdapterbjdcPassSingle.clearAllDate();
			App.totalCount = 0;
			for (int i = 0; i < App.activityS1.size(); i++) {
				App.activityS1.get(i).finish();
			}
		}
	}

	/** 重写返回键事件 */
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			backToPre();
		}
		return super.onKeyDown(keyCode, event);
	}
	class PayAsynTask extends AsyncTask<Integer, Integer, String> {

		String error = "-1";


		@Override
		protected String doInBackground(Integer... params) {

			opt = "85";
			time = RspBodyBaseBean.getTime();
			imei = RspBodyBaseBean.getIMEI(Bet_BJDC_Activity.this);


				info = RspBodyBaseBean.change_TheSun2(App.schemeId + "", "", Utils.decimalFormat((max_jiangjin * App.bei)) +"", adapter.bet_List_Matchs.get(0).getStopSellTime(), "1");



			String key = App.key;
			crc = RspBodyBaseBean.getCrc(time, imei, key, info, App.user.getUid());
			auth = RspBodyBaseBean.getAuth(crc, time, imei, App.user.getUid());
			String[] values = { opt, auth, info };
//			Log.i(TAG, "晒单" + RequestParams.convertParams(context, opt, info));
			String result = HttpUtils.doPost(App.names, values, App.path);
			System.out.println("晒单：" + result);
			if (result.equals("success")) {
				error = "1";
			} else {
				error = "-1";
			}

			return error;
		}

		@Override
		protected void onPostExecute(String result) {
			myHandler.sendEmptyMessage(Integer.parseInt(result));
			super.onPostExecute(result);
		}
	}
	/*** 异步任务 用来后台获取数据 */
	class MyAsynTask extends AsyncTask<Void, Integer, String> {
		/** 在后台执行的程序 */
		@Override
		protected String doInBackground(Void... params) {
			String error = "-1";
			if (App.list_numbers.size() > 0) {
				time = RspBodyBaseBean.getTime();
				imei = RspBodyBaseBean.getIMEI(getApplicationContext());

				if (App.user != null) {
					String key = MD5.md5(App.user.getUserPass()
							+ App.MD5_key);
					info = RspBodyBaseBean.changeBet_info2(
							App.lottery.getLotteryID(),
							App.lottery.getIsuseId(), App.bei, 1, 1,
							0, 0, "", "", 0, totalMoney / App.qi,
							sumCount, App.qi > 1 ? App.qi : 0,
							App.qi == 1 ? 0 : totalMoney,
							App.list_numbers, isStopChase);
					crc = RspBodyBaseBean.getCrc(time, imei, key, info,
							App.user.getUid());

					auth = RspBodyBaseBean.getAuth(crc, time, imei,
							App.user.getUid());
					String values[] = { opt, auth, info };
					String result = HttpUtils.doPost(App.names, values,
							App.path);
					System.out.println("info==" + info);
					System.out.println("result==" + result);
					if ("-500".equals(result))
						return result;
					try {
						JSONObject object = new JSONObject(result);
						error = object.optString("error");
						if ("0".equals(error)) {
							App.user.setBalance(object
									.optDouble("balance"));
							App.user.setFreeze(object.optDouble("freeze"));
							App.schemeId = object.optInt("schemeids");
							App.lottery.setChaseTaskID(object
									.optInt("chasetaskids"));
							App.list_numbers.clear();
							SucJinECost = format.format(object
									.optDouble("currentMoeny"));
							SucCaiJinCost = format.format(object
									.optDouble("currentHandsel"));
							SuccMoney = format.format(object
									.optDouble("handselMoney"));
						}
					} catch (JSONException e) {
						e.printStackTrace();
						error = "-1";
					}
				} else {
					return "-100";
				}
			} else {
				return "-102";
			}
			return error;
		}

		@Override
		protected void onPostExecute(String result) {
			myHandler.sendEmptyMessage(Integer.parseInt(result));
			super.onPostExecute(result);
		}
	}

	/** 处理页面显示的 */
	@SuppressLint("HandlerLeak")
	class MyHandler extends Handler {
		@Override
		public void handleMessage(Message msg) {
			setEnabled(true);
			switch (msg.what) {
			case App.ERROR_SUCCESS:

				PayAsynTask payAsynTask = new PayAsynTask();
				payAsynTask.execute();


				break;
				case 1:
					App.list_numbers.clear();
					App.totalCount = 0;
					// 清空所有数据
					ExpandAdapterbjdcPassMore.clearAllDate();
					ExpandAdapterbjdcPassSingle.clearAllDate();
					selectPasstype.clear();// 清除过关方式
					viewPagerCurrentIndex = 0;// 过关类型 0.多串1 1.多串多
					Intent intent = new Intent(getApplicationContext(),
							PaySuccessActivity.class);

					intent.putExtra("paymoney", totalMoney);
					intent.putExtra("currentMoeny", SucJinECost);
					intent.putExtra("currentHandsel", SucCaiJinCost);
					intent.putExtra("handselMoney", SuccMoney);
					Bet_BJDC_Activity.this.startActivity(intent);
					break;
			/** 余额不足 **/
			case App.ERROR_MONEY:
				Toast.makeText(Bet_BJDC_Activity.this, "余额不足",
						Toast.LENGTH_SHORT).show();
				// intent = new
				// Intent(Bet_BJDC_Activity.this,RechargeActivity.class);
				// intent.putExtra("money", totalMoney);
				Intent intent_alipay = new Intent();
				Bundle bundle_alipay = new Bundle();
				intent_alipay.setClass(Bet_BJDC_Activity.this,
						AmountOfCharge.class);
				bundle_alipay.putInt("Type", 1);
				intent_alipay.putExtras(bundle_alipay);
				startActivity(intent_alipay);
				// intent = new Intent();
				// intent.setClass(Bet_BJDC_Activity.this,
				// PayWebActivity.class);
				// Bet_BJDC_Activity.this.startActivity(intent);
				break;
			/** 尚未登陆 **/
			case App.ERROR_UNLONGIN:
				MyToast.getToast(Bet_BJDC_Activity.this, "请先登陆").show();
				intent = new Intent(Bet_BJDC_Activity.this, LoginActivity.class);
				intent.putExtra("loginType", "bet");
				Bet_BJDC_Activity.this.startActivity(intent);
				break;
			/** 点击付款时 所选注数为 0 **/
			case App.ERROR_TOTAL:
				MyToast.getToast(Bet_BJDC_Activity.this, "请至少选择一注").show();
				intent = new Intent(Bet_BJDC_Activity.this,
						SelectNumberActivity.class);
				intent.putExtra("loginType", "bet");
				Bet_BJDC_Activity.this.startActivity(intent);
				break;
			case -500:
				MyToast.getToast(Bet_BJDC_Activity.this, "连接超时").show();
				break;
			default:
				Toast.makeText(Bet_BJDC_Activity.this, "网络异常，购买失败。请重新点击付款购买。",
						Toast.LENGTH_SHORT).show();
				break;
			}

			if (myAsynTask != null
					&& myAsynTask.getStatus() == AsyncTask.Status.RUNNING) {
				myAsynTask.cancel(true); // 如果Task还在运行，则先取消它
			}
			Log.i("x", "执行了");
			super.handleMessage(msg);

		}
	}

	@Override
	protected void onResume() {
		super.onResume();
		init();
		setListener();
		et_bei.setText("1");
		if (1 == passtype) {// 单关
			initPassType();// 初始化过关方式
			setSelectNumAndGetCount();// 设置投注格式和注数
		}
		changeTextShow();
	}

	@Override
	protected void onNewIntent(Intent intent) {
		setIntent(intent);
		super.onNewIntent(intent);
	}

	/** 给总注数赋值 有胆的情况下 **/
	public void setTotalCount(String type, List<String> list_dan,
			List<String> list) {
		if (type.contains("AA"))// 2串1
			this.sumCount += NumberTools.getAllnG1Mixed_dan(list_dan, list, 2);
		if (type.contains("AC"))
			this.sumCount += NumberTools.getAllnG1Mixed_dan(list_dan, list, 3);
		if (type.contains("AF"))
			this.sumCount += NumberTools.getAllnG1Mixed_dan(list_dan, list, 4);
		if (type.contains("AJ"))
			this.sumCount += NumberTools.getAllnG1Mixed_dan(list_dan, list, 5);
		if (type.contains("AO"))
			this.sumCount += NumberTools.getAllnG1Mixed_dan(list_dan, list, 6);
		if (type.contains("AU"))
			this.sumCount += NumberTools.getAllnG1Mixed_dan(list_dan, list, 7);
		if (type.contains("AV"))
			this.sumCount += NumberTools.getAllnG1Mixed_dan(list_dan, list, 8);
		if (type.contains("AW"))
			this.sumCount += NumberTools.getAllnG1Mixed_dan(list_dan, list, 9);
		if (type.contains("AX"))
			this.sumCount += NumberTools.getAllnG1Mixed_dan(list_dan, list, 10);
		if (type.contains("AY"))
			this.sumCount += NumberTools.getAllnG1Mixed_dan(list_dan, list, 11);
		if (type.contains("AZ"))
			this.sumCount += NumberTools.getAllnG1Mixed_dan(list_dan, list, 12);
		if (type.contains("BA"))
			this.sumCount += NumberTools.getAllnG1Mixed_dan(list_dan, list, 13);
		if (type.contains("BB"))
			this.sumCount += NumberTools.getAllnG1Mixed_dan(list_dan, list, 14);
		if (type.contains("BC"))
			this.sumCount += NumberTools.getAllnG1Mixed_dan(list_dan, list, 15);
		// 2-3 3-4 3-7 4-5 4-11 4-15 5/6-16-26-31 6/7-22-42-57-63
		if (type.contains("AB"))
			this.sumCount += NumberTools
					.getAll2G3Mixed_dan_bjdc(list_dan, list);
		if (type.contains("AD"))
			this.sumCount += NumberTools.getAll3G4Mixed_dan(list_dan, list);
		if (type.contains("AE"))
			this.sumCount += NumberTools
					.getAll3G7Mixed_dan_bjdc(list_dan, list);
		if (type.contains("AG"))
			this.sumCount += NumberTools.getAll4G5Mixed_dan(list_dan, list);
		if (type.contains("AH"))
			this.sumCount += NumberTools.getAll4G6_11Mixed_dan(list_dan, list,
					11);
		if (type.contains("AI"))
			this.sumCount += NumberTools.getAll4G15Mixed_dan_bjdc(list_dan,
					list);
		if (type.contains("AK"))
			this.sumCount += NumberTools.getAll5G6Mixed_dan(list_dan, list);
		if (type.contains("AL"))
			this.sumCount += NumberTools.getAll5G10_16_20Mixed_dan(list_dan,
					list, 16);
		if (type.contains("AM"))
			this.sumCount += NumberTools.getAll5G26Mixed_dan(list_dan, list);
		if (type.contains("AN"))
			this.sumCount += NumberTools.getAll5G31Mixed_dan_bjdc(list_dan,
					list);
		if (type.contains("AP"))
			this.sumCount += NumberTools.getAll6G7Mixed_dan(list_dan, list);
		if (type.contains("AQ"))
			this.sumCount += NumberTools.getAll6G15_20_22_50Mixed_dan(list_dan,
					list, 22);
		if (type.contains("AR"))
			this.sumCount += NumberTools.getAll6G42Mixed_dan(list_dan, list);
		if (type.contains("AS"))
			this.sumCount += NumberTools.getAll6G57Mixed_dan(list_dan, list);
		if (type.contains("AT"))
			this.sumCount += NumberTools.getAll6G63Mixed_dan_bjdc(list_dan,
					list);

	}

	/** 给总注数赋值 没胆的情况下 **/
	public void setTotalCount(String type, List<String> list) {
		if (type.contains("A0"))
			this.sumCount += NumberTools.getCountBySinglePass(list);
		if (type.contains("AA"))
			this.sumCount += NumberTools.getAll2G1Mixed(list);
		if (type.contains("AB"))
			this.sumCount += NumberTools.getAll2G3Mixed_bjdc(list);
		if (type.contains("AC"))
			this.sumCount += NumberTools.getAll3G1Mixed(list);
		if (type.contains("AD"))
			this.sumCount += NumberTools.getAll3G4Mixed(list);
		if (type.contains("AE"))
			this.sumCount += NumberTools.getAll3G7Mixed_bjdc(list);
		if (type.contains("AF"))
			this.sumCount += NumberTools.getAll4G1Mixed(list);
		if (type.contains("AG"))
			this.sumCount += NumberTools.getAll4G5Mixed(list);
		if (type.contains("AH"))
			this.sumCount += NumberTools.getAll4G11Mixed(list);
		if (type.contains("AI"))
			this.sumCount += NumberTools.getAll4G15Mixed_bjdc(list);
		if (type.contains("AJ"))
			this.sumCount += NumberTools.getAll5G1Mixed(list);
		if (type.contains("AK"))
			this.sumCount += NumberTools.getAll5G6Mixed(list);
		if (type.contains("AL"))
			this.sumCount += NumberTools.getAll5G16Mixed(list);
		if (type.contains("AM"))
			this.sumCount += NumberTools.getAll5G26Mixed(list);
		if (type.contains("AN"))
			this.sumCount += NumberTools.getAll5G31Mixed_bjdc(list);
		if (type.contains("AO"))
			this.sumCount += NumberTools.getAll6G1Mixed(list);
		if (type.contains("AP"))
			this.sumCount += NumberTools.getAll6G7Mixed(list);
		if (type.contains("AQ"))
			this.sumCount += NumberTools.getAll6G22Mixed(list);
		if (type.contains("AR"))
			this.sumCount += NumberTools.getAll6G42Mixed(list);
		if (type.contains("AS"))
			this.sumCount += NumberTools.getAll6G57Mixed(list);
		if (type.contains("AT"))
			this.sumCount += NumberTools.getAll6G63Mixed_bjdc(list);
		if (type.contains("AU"))
			this.sumCount += NumberTools.getAll7G1Mixed(list);
		if (type.contains("AV"))
			this.sumCount += NumberTools.getAll8G1Mixed(list);
		if (type.contains("AW"))
			this.sumCount += NumberTools.getAll9G1Mixed(list);
		if (type.contains("AX"))
			this.sumCount += NumberTools.getAll10G1Mixed(list);
		if (type.contains("AY"))
			this.sumCount += NumberTools.getAll11G1Mixed(list);
		if (type.contains("AZ"))
			this.sumCount += NumberTools.getAll12G1Mixed(list);
		if (type.contains("BA"))
			this.sumCount += NumberTools.getAll13G1Mixed(list);
		if (type.contains("BB"))
			this.sumCount += NumberTools.getAll14G1Mixed(list);
		if (type.contains("BC"))
			this.sumCount += NumberTools.getAll15G1Mixed(list);
	}

}
